<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
	<head>
		<base href="<%=basePath%>">
		<title>首页</title>
		<script type="text/javascript">
			function addp(name) {
				var headerurl = "http://localhost:8080/Gfs09_25/";
				var uri = headerurl+"uc/yaddp?uname="+name;
				window.location.href = uri;
			}
			function update(name,pid) {
				var d = document.getElementsByName("pnum");
				var pnum = d[0].value;
				
				d = document.getElementsByName("address");
				var address = d[0].value;
				var toSid = document.getElementById("toSid").value;
				
				var headerurl = "http://localhost:8080/Gfs09_25/";
				var uri = headerurl+"pc/truUpdate?uname="+name+"&pid="
						+pid+"&pnum="+pnum+"&address="+address+"&toSid="+toSid;
				window.location.href = uri;
			}
			function ud(type,name,id) {
				var headerurl = "http://localhost:8080/Gfs09_25/";
				var uri = headerurl;
				if (type==0) {
					uri = uri+"pc/update?uname="+name+"&pid="+id;
				}
				if (type==1) {
					uri = uri+"pc/delete?uname="+name+"&pid="+id;
				}
				window.location.href = uri;
			}
		</script>
	</head>

	<body><br>
	
		<button onclick="addp('${requestScope.uname}')">
			添加商品信息
		</button><br><br>
		<div>
			<form action="uc/first" method="post">
				跳转到&nbsp; <input width="20px" name="sid" type="number" value="1" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = '1';}" />仓库
				<input type="hidden" name="name" value="${requestScope.uname }" />
				<button>跳转</button>
			</form>
		</div><br><br>
		<table border="1">
			<thead>
				<tr>
					<td>仓库${requestScope.storage.id}的剩余存量：  ${requestScope.storage.syNum}</td>
				</tr>
			</thead>
			<tr>
				<th>商品编号</th>
				<th>商品名</th>
				<th>商品数量</th>
				<th>商品单价</th>
				<c:if test="${!empty requestScope.update }">
					<th>调出数量</th>
				</c:if>
				<c:if test="${!empty requestScope.update }">
					<th>调出目的地</th>
				</c:if>
				<c:if test="${!empty requestScope.update }">
					<th>调出到仓库</th>
				</c:if>
				<th>操作</th>
			</tr>
			<c:forEach items="${requestScope.allp}" var="ap">
				<tr>
					<td>${ap.id }</td>
					<td>${ap.name }</td>
					<td>${ap.num }</td>
					<td>${ap.price }</td>
					<c:if test="${(!empty requestScope.update)&&(requestScope.pid==ap.id) }">
						<td>
							<input name="pnum" value="1" type="number" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = '1';}" />
						</td>
					</c:if>
					<c:if test="${(!empty requestScope.update)&&(requestScope.pid==ap.id) }">
						<td>
							<input name="address" value="1" type="text" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = '1';}" />
						</td>
					</c:if>
					<c:if test="${(!empty requestScope.update)&&(requestScope.pid==ap.id) }">
						<td>
							<select id="toSid">
								<c:forEach items="${requestScope.storageAll }" var="sa">
									<c:if test="${sa.id==requestScope.storage.id }">
										<option value="${sa.id }" selected="selected">${sa.name }</option>
									</c:if>
									<c:if test="${sa.id!=requestScope.storage.id }">
										<option value="${sa.id }">${sa.name }</option>
									</c:if>
								</c:forEach>
							</select>
						</td>
					</c:if>
					<td>
						<c:if test="${(!empty requestScope.update)&&(requestScope.pid==ap.id) }">
							<button onclick="update('${requestScope.uname }','${ap.id }')">调出</button>
						</c:if>
						<c:if test="${empty requestScope.update  }">
							<button onclick="ud(0,'${requestScope.uname }','${ap.id }')">调出</button>&nbsp;
							<button onclick="ud(1,'${requestScope.uname }','${ap.id }')">删除</button>
						</c:if>
					</td>
				</tr>
			</c:forEach>
		</table>
	</body>
</html>